import{Mongoose,Schema,Model,Document} from 'mongoose';
import { BaseDao} from './BaseDao';
import{ User} from '../models/User';
import{ Group} from '../models/Group';
export class GroupsDao extends BaseDao
{
  groupModel:Model<any>;
  constructor(){
    super();
    this.groupModel = this.dbManager.getModel("mGroup");
  }
  add(group:Group,callback:Function)
  {
    var group_ = new this.groupModel(group);
    group_.save(callback);
  }

  update(group:Group,callback:Function)
  {
    var query = {_id:group._id};
    var updater = {
      "name":group.name,
      "description":group.description
    };
    this.groupModel.update(query,updater,callback);
  }

  get(groupId:string,callback:Function)
  {
    this.groupModel.findOne({_id:groupId}).populate("project").exec(callback);
  }

  gets(projectId:string,callback:Function)
  {
    this.groupModel.find({project:projectId}).populate("project").exec(callback);
  }

  delete(groupId:string,callback:Function)
  {
    this.groupModel.remove({_id:groupId}).exec(callback);
  }
}
